package com.blog.backend.controller;


import com.blog.backend.annotation.LoginAnno;
import com.blog.backend.req.FoodReq;
import com.blog.backend.req.ListFoodReq;
import com.blog.backend.resp.FoodResp;
import com.blog.backend.service.FoodService;
import com.blog.backend.utils.Result;
import com.blog.backend.vo.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/food")
@Api("美食管理")
public class FoodController {

    @Autowired
    private FoodService foodService;


    @PostMapping("/insertFood")
    @ApiOperation("新增食品")
    @LoginAnno
    public Result<Boolean> insertFood(@RequestBody FoodReq foodReq){
       Boolean result= foodService.insertFood(foodReq);
        return Result.success(result);
    }

    @PostMapping("/selectFoodList")
    @LoginAnno
    @ApiOperation("查询食品列表")
    public Result<PageResult<FoodResp>> selectFoodList(@RequestBody ListFoodReq req){
        PageResult<FoodResp> pageResult=  foodService.selectFoodList(req);
        return Result.success(pageResult);
    }

    @GetMapping("/selectFoodDetail")
    @LoginAnno
    @ApiOperation("查看食品详情")
    public Result<FoodResp> selectFoodDetail(@RequestParam String foodId){
        FoodResp resp= foodService.selectFoodDetail(foodId);
        return Result.success(resp);
    }

    @PostMapping("/updateFoodDetail")
    @LoginAnno
    @ApiOperation("/更新食品详情")
    public Result<Boolean> updateFoodDetail(@RequestBody FoodReq foodReq){
        Boolean result=foodService.updateFoodDetail(foodReq);
        return Result.success(result);
    }

    @GetMapping("/deleteFood")
    @LoginAnno
    @ApiOperation("/删除食品信息")
    public Result<Boolean> deleteFood(@RequestParam String foodId){
        Boolean result=foodService.deleteFood(foodId);
        return Result.success(result);
    }
}
